#include "WINApt_Hdr.h"

void WINApt_Callback_Login(LPCTSTR lpszClientAddr,SOCKET hSocket,BOOL bIsCtrl,LPVOID lParam)
{
    XLOG_PRINT(xhLog,NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO,_T("客户端：%s，进入了服务器"),lpszClientAddr);
    HelpComponents_Datas_CreateEx(xhTCPPacket,lpszClientAddr);
}
void WINApt_Callback_Recv(LPCTSTR lpszClientAddr,SOCKET hSocket,LPCTSTR lpszRecvMsg,int nMsgLen,BOOL bIsCtrl,LPVOID lParam)
{
    if (HelpComponents_Datas_PostEx(xhTCPPacket,lpszClientAddr,lpszRecvMsg,nMsgLen))
    {
        XLOG_PRINT(xhLog,NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_DEBUG,_T("客户端：%s，投递包成功，大小：%d"),lpszClientAddr,nMsgLen);
    }
    else
    {
        XLOG_PRINT(xhLog,NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR,_T("客户端：%s，投递包失败，大小：%d,错误：%lX"),lpszClientAddr,nMsgLen,Packets_GetLastError());
    }
}
void WINApt_Callback_Leave(LPCTSTR lpszClientAddr,SOCKET hSocket,BOOL bIsCtrl,LPVOID lParam)
{
    XLOG_PRINT(xhLog,NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_INFO,_T("客户端：%s，离开了服务器"),lpszClientAddr);
    WINApt_CloseClient(lpszClientAddr);
}

void WINApt_CloseClient(LPCTSTR lpszClientAddr)
{
    HelpComponents_Datas_DeleteEx(xhTCPPacket,lpszClientAddr);
}
void WINApt_SendMsg_Client(LPCTSTR lpszClientAddr,LPCTSTR lpszMsgBuffer,int nMsgLen)
{
    if (!NetCore_TCPEPoll_SendEx(xhTCPNet,lpszClientAddr,lpszMsgBuffer,nMsgLen))
    {
        XLOG_PRINT(xhLog,NETENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR,_T("发送数据给客户端：%s，失败，发送大小：%d，错误：%lX,%d"),lpszClientAddr,nMsgLen,NetCore_GetLastError(),errno);
    }
}
